//
//  MemerBroswerHistoryViewController.m
//  LiteraryTune
//
//  Created by 陈雪丹 on 2018/2/4.
//  Copyright © 2018年 cxd. All rights reserved.
//

#import "MemerBroswerHistoryViewController.h"
#import "MemberCenterTopTableViewCell.h"
#import "TopTitleView.h"
#import "BookCollectCell.h"
#import "BroswerHistoryCell.h"
#import "BrowserHistoryModel.h"
#import "BookDetailShowViewController.h"

@interface MemerBroswerHistoryViewController () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong)UITableView *myTableView;
@property (nonatomic, strong)TopTitleView *topView;
//数据源
@property (nonatomic, strong)NSArray *dataArr;


@end

@implementation MemerBroswerHistoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"浏览记录";
    [self getNetData];
    [self buildUI];
}

- (void)getNetData {
    NSString *userName = [CXDHelper getUserAccountName];
    if (userName.length == 0) {
        [CXDNoticeView showNoticeViewWithString:@"您还未登陆，请先进行登陆"];
    }else {
        [CXDNetHelp getRequestWithURLString:[NSString stringWithFormat:@"%@%@",BrowsingHistoryURL,[CXDHelper getUserAccountName]] parameters:nil success:^(id  _Nullable responseObject) {
            NSLog(@"浏览记录 %@",responseObject);
            _dataArr = [NSArray yy_modelArrayWithClass:[BrowserHistoryModel class] json:responseObject];
            [self.myTableView reloadData];
        } failure:^(NSError * _Nullable error) {
            
        }];
    }
}

- (void)buildUI {
    [self.view addSubview:self.myTableView];
}

- (UITableView *)myTableView {
    if (!_myTableView) {
        _myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - CXDTopHeight) style:UITableViewStylePlain];
        _myTableView.delegate = self;
        _myTableView.dataSource = self;
        _myTableView.rowHeight = 110;
        _myTableView.backgroundColor = [UIColor colorFromHexCode:@"#eeeeee"];
        _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _myTableView.showsVerticalScrollIndicator = NO;
        [_myTableView registerNib:[UINib nibWithNibName:NSStringFromClass([BroswerHistoryCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([BroswerHistoryCell class])];
    }
    return _myTableView;
}
#pragma mark - 协议实现
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BroswerHistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([BroswerHistoryCell class])];
    BrowserHistoryModel *tempModel = _dataArr[indexPath.row];
    cell.dataMdoel = tempModel;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    BrowserHistoryModel *tempModel = _dataArr[indexPath.row];
//    if ([tempModel.fname isEqualToString:@"图书"]) {
//        BookDetailShowViewController *detailVC = [[BookDetailShowViewController alloc] init];
//        detailVC.navigationItem.title = tempModel.bname;
//        detailVC.bookId = tempModel.bookID;
//        [self.navigationController pushViewController:detailVC animated:YES];
//    }
}


@end
